// KnownStandardSet.cpp: implementation of the KnownStandardSet class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "KnownStandardSet.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

KnownStandardSet::KnownStandardSet()
{

}

KnownStandardSet::~KnownStandardSet()
{

}

StandardInfo* KnownStandardSet::ReadStandardInfo()
{
	StandardInfo* pInfo = new StandardInfo;

	pInfo->StandardID(vtos(m_rs->GetCollect(_T("StandardID"))));
	pInfo->StandardPath(vtos(m_rs->GetCollect(_T("DBPath"))));
	pInfo->StandardInfoTable(vtos(m_rs->GetCollect(_T("StandardInfoTable"))));
	pInfo->StandardStyle(vtoi(m_rs->GetCollect(_T("StandardStyle"))));

	return pInfo;
}

BOOL KnownStandardSet::AddStandardSet(StandardSet& set)
{
	StandardInfo* pInfo = set.GetFirst();

	try
	{
	while(pInfo != NULL)
	{
		GetRecordSet()->AddNew();
		GetRecordSet()->PutCollect(_T("StandardID"), _variant_t(pInfo->StandardID()));
		GetRecordSet()->PutCollect(_T("DBPath"), _variant_t(pInfo->StandardPath()));
		GetRecordSet()->PutCollect(_T("StandardInfoTable"), _variant_t(pInfo->StandardInfoTable()));
		GetRecordSet()->PutCollect(_T("StandardStyle"), _variant_t((short)pInfo->StandardStyle()));

		pInfo = set.GetNext();
	}
	GetRecordSet()->UpdateBatch(adAffectAll);
	}
	CATCH_COM_ERROR(_RecordsetPtr(), FALSE)

	return TRUE;
}

BOOL KnownStandardSet::DeleteStandard(StandardInfo& info)
{
	return DeleteStandard(info.StandardID());
}

BOOL KnownStandardSet::DeleteStandard(const CString& strStandardID)
{
	CString strSql;
	strSql.Format(_T("Delete * from Standard where StandardID = '%s'"), strStandardID);

	try
	{
		_ConnectionPtr pCon = GetRecordSet()->DataSource;
		pCon->Execute(_bstr_t(strSql), NULL, adCmdText);
	}
	CATCH_COM_ERROR(_RecordsetPtr(), FALSE)

	return TRUE;
}